package methodOnde;

import java.util.ArrayList;

public class StringB {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        Student s1=new Student("梨花",18);
        Student s2=new Student("小明",19);
        Student s3=new Student("张飞",25);
        students.add(s1);
        students.add(s2);
        students.add(s3);
        ArrayList<Student> method = method(students);
        for (int i = 0; i < method.size(); i++) {
            Student student=method.get(i);
            System.out.println(student.getName()+"..."+student.getAge());
        }


    }

    public static ArrayList<Student> method(ArrayList<Student> list) {
        //方法内部定义新集合，准备存储筛选出的学生对象ArrayList<Student>
     ArrayList<Student> newList=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            //遍历原集合，获取每一个学生对象
            Student student=list.get(i);
            int age=student.getAge();
            if(age>18)
                newList.add(student);
        }
    return newList;
    }
}
